package com.yunfeng.supercall.fragment;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Formatter.BigDecimalLayoutForm;
import java.util.Iterator;
import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.lin.activity.AddFriendActivity;
import com.lin.activity.EntrepriseDynamicActivity;
import com.lin.activity.FriendsShareWallActivity;
import com.lin.activity.TestDatabasePOIActivity;
import com.lin.utils.DatabaseHelperForChattingMap;
import com.lin.utils.Parameters;
import com.lin.utils.Session;
import com.lin.utils.Utils;
import com.lin.views.CustomPopupWindow;
import com.ly.quickdev.library.adapter.ListBaseAdapter.ViewHolder;
import com.ly.quickdev.library.fragment.DevBaseListFragment;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.yunfeng.supercall.R;
import com.yunfeng.supercall.activity.AddSuperFriendsActivity;
import com.yunfeng.supercall.activity.BaseActivity;
import com.yunfeng.supercall.activity.ChatActivity;
import com.yunfeng.supercall.activity.FriendShareListActivity;
import com.yunfeng.supercall.activity.SearchUserActivity;
import com.yunfeng.supercall.bean.AdsBean;
import com.yunfeng.supercall.bean.ChatMessageBean;
import com.yunfeng.supercall.bean.Constants;
import com.yunfeng.supercall.bean.ContactsBaseBean;
import com.yunfeng.supercall.bean.SuperFriendsBean;
import com.yunfeng.supercall.bean.SystemContactsBean;
import com.yunfeng.supercall.bean.UserBean;
import com.yunfeng.supercall.iface.MessageAccessable;
import com.yunfeng.supercall.manager.AdsManager;
import com.yunfeng.supercall.manager.ChatMessageManager;
import com.yunfeng.supercall.manager.ManagerFactory;
import com.yunfeng.supercall.manager.SuperFriendsManager;

public class RecentChatListFragment extends DevBaseListFragment<ContactsBaseBean>
implements Constants, MessageAccessable {
	private SwipeRefreshLayout mSwipeRefreshLayout;

	ChatMessageManager mChatMessageManager;
	public static final String PATTERN = "yyyy-MM-dd HH:mm";

	public static final String PATTERN1 = "HH:mm";
	private SimpleDateFormat mDateFormat;
	CustomPopupWindow pw;
	View mView;
	DisplayImageOptions options;
	private UpdateBroadcastReceiver mUpdateBroadcastReceiver;
	Session mSession;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		Log.i("tagtest", "onCreateView");

		options = new DisplayImageOptions.Builder()
		.displayer(new RoundedBitmapDisplayer(getActivity().getResources().getDimensionPixelSize(R.dimen.corners_avatar)))
		.showImageOnFail(R.drawable.default_avatar)
		.showImageOnLoading(R.drawable.default_avatar)
		.cacheInMemory(true)
		.cacheOnDisk(true)
		.considerExifParams(true)
		.bitmapConfig(Bitmap.Config.RGB_565)
		.build();

		mView = inflater.inflate(R.layout.fragment_recent_chat_list, null);
		pw = new CustomPopupWindow(getActivity());
		FrameLayout  mFrameLayoutMore = (FrameLayout) mView.findViewById(R.id.framelayout_more);
		mListView = (PullToRefreshListView) mView.findViewById(R.id.list);
		
		mFrameLayoutMore.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				pw.show();
			}
		});

		
		mImageViewMore = (ImageView) mView.findViewById(R.id.imageview_more);
		mImageViewMore.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				pw.show();
			}
		});
		
		
		mSwipeRefreshLayout = (SwipeRefreshLayout) mView.findViewById(R.id.swipe);

		mSwipeRefreshLayout.setRefreshing(true);
		mSwipeRefreshLayout.setColorSchemeResources(R.color.base_orange);

		mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

			@Override
			public void onRefresh() {
				load();
			}
		});

		FrameLayout mFrameLayoutSearch = (FrameLayout) mView.findViewById(R.id.framelayout_search);
		mFrameLayoutSearch.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivity(new Intent(getActivity(), AddFriendActivity.class));
			}
		});

		IntentFilter filter = new IntentFilter();
		filter.addAction(ACTION_RECEIVE_MSG);
		mUpdateBroadcastReceiver = new UpdateBroadcastReceiver();
		getActivity().registerReceiver(mUpdateBroadcastReceiver, filter);

		IntentFilter filter2 = new IntentFilter();
		filter2.addAction(ACTION_RECEIVE_MSG2);
		mUpdateBroadcastReceiver2 = new UpdateBroadcastReceiver2();
		getActivity().registerReceiver(mUpdateBroadcastReceiver2, filter2);
		mSession = Session.getSession();
		mSession.init(getActivity(), true);
		userBean = mSession.getmUserBean();
		Log.i("tagtest", "onCreateViewAfter");
		load();
		return mView;
	}



	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if(mUpdateBroadcastReceiver != null) {
			getActivity().unregisterReceiver(mUpdateBroadcastReceiver);
			mUpdateBroadcastReceiver = null;
		}
		if(mUpdateBroadcastReceiver2 != null) {
			getActivity().unregisterReceiver(mUpdateBroadcastReceiver2);
			mUpdateBroadcastReceiver2 = null;
		}

	}



	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mChatMessageManager = ChatMessageManager.getInstance(getActivity());
		mList = new ArrayList<ContactsBaseBean>();
		mDateFormat = new SimpleDateFormat(PATTERN);
		
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		//		AdsManager mAdsManager = (AdsManager) ManagerFactory
		//				.createManager(AdsBean.class);
		//		mAdsManager.addAdsHeader(mListView.getRefreshableView(), 0);
		super.onActivityCreated(savedInstanceState);

		setEmptyMessage(getString(R.string.no_chat));
		View search = findViewById(R.id.search_area);
		if (search != null) {
			search.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					startActivity(new Intent(getActivity(),
							SearchUserActivity.class));
				}
			});
		}
		View add = findViewById(R.id.add_friends_area);
		if (add != null) {
			add.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					startActivity(new Intent(getActivity(),
							AddSuperFriendsActivity.class));
				}
			});
		}

	}

	@Override
	public Mode getRefreshMode() {
		return Mode.DISABLED;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			if (position == 0) {
				convertView = getActivity().getLayoutInflater().inflate(
						R.layout.list_item_system_friends, null);
				iv = (ImageView) convertView.findViewById(R.id.iv);
				ImageLoader.getInstance().displayImage("drawable://" + R.drawable.ic_entreprisedynamic, iv, options);
			} else if(position == 1) {
				convertView = getActivity().getLayoutInflater().inflate(
						R.layout.list_item_system_friends, null);
				iv = (ImageView) convertView.findViewById(R.id.iv);
				ImageLoader.getInstance().displayImage("drawable://" + R.drawable.ic_msg, iv, options);
			} else {
				convertView = getActivity().getLayoutInflater().inflate(
						R.layout.list_item_recent_chating, null);
			}

		}

		iv = (ImageView) convertView.findViewById(R.id.iv);
		ContactsBaseBean base = mList.get(position);

		//主要是为了区分 企业动态 和 普通用户留言
		ContactsBaseBean.setupSingleLineContactsView(convertView, base);
		if (base instanceof SuperFriendsBean) {
			final TextView red = ViewHolder.get(convertView, R.id.red_dot);
			final TextView content = ViewHolder.get(convertView, R.id.content);
			final TextView date = ViewHolder.get(convertView, R.id.date);
			ArrayList<ChatMessageBean> chatMessages = findChatMessages(base);
			ImageLoader.getInstance().displayImage(Parameters.SERVER_PIC_URL + base.getPhoto(), iv, options);

			/*List<ChatMessageBean> chatMessages = mChatMessageManager
					.findChatMessages(base);*/
			/*List<ChatMessageBean> chatMessages = mChatMessageManager.findAllChatMessages();*/
			red.setVisibility(base.isUnread() ? View.VISIBLE : View.GONE);
			red.setVisibility(View.VISIBLE);
			int count = base.getUnreadCount();
			red.setVisibility(count == 0 ? View.INVISIBLE : View.VISIBLE);
			red.setText(base.getUnreadCount() + "");
			int size = chatMessages.size();
			if (size > 0) {
				ChatMessageBean message = chatMessages.get(size - 1);
				String text = "";
				switch (message.getChatType()) {
				case ChatMessageBean.TYPE_PIC:
					text = "[图片]";
					break;
				case ChatMessageBean.TYPE_VOICE:
					text = "[语音]";
					break;
				case ChatMessageBean.TYPE_LOCATION:
					text = "[位置]";
					break;
				default:
					text = message.getContent();
					break;
				}

				if (date != null) {
					SimpleDateFormat dateFormat = new SimpleDateFormat(PATTERN1);
					Calendar now = Calendar.getInstance();
					Calendar calendar = Calendar.getInstance();
					calendar.setTimeInMillis(message.getReceiveTime());
					int i = now.get(Calendar.DAY_OF_YEAR);
					int j = calendar.get(Calendar.DAY_OF_YEAR);
					if (i == j) {
						date.setText(dateFormat.format(new Date(message
								.getReceiveTime())));
					} else if (i - j == 2) {
						date.setText("前天："
								+ dateFormat.format(new Date(message
										.getReceiveTime())));
					} else if (i - j == 1) {
						date.setText("昨天："
								+ dateFormat.format(new Date(message
										.getReceiveTime())));
					} else {
						date.setText(mDateFormat.format(new Date(message
								.getReceiveTime())));
					}

				}
				if (content != null) {
					content.setText(text);
				}
			}
		}
		
		return convertView;
	}

	@Override
	public int getItemViewType(int position) {
		if (position == 0) {
			return 0;
		}
		return 1;
	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
	}

	@Override
	public void onResume() {
		super.onResume();
		

	}

	ArrayList<ChatMessageBean> mListChatMessageBean = new ArrayList<ChatMessageBean>();
	private UpdateBroadcastReceiver2 mUpdateBroadcastReceiver2;
	private Cursor cursor2;
	private SQLiteDatabase db7;
	private DatabaseHelperForChattingMap dbHelper7;
	private ImageView iv;

	private ImageView mImageViewMore;

	private UserBean userBean; 

	public void load() {
		Log.i("tagtest", "loadbefore");

		if (mList == null) {
			mList = new ArrayList<ContactsBaseBean>();
		}
		mList.clear();
		SystemContactsBean mContacts = new SystemContactsBean();
		mContacts.setImgId(R.drawable.ic_entreprisedynamic);
		mContacts.setReal_name("官方资讯");
		mList.add(mContacts);

		mContacts = new SystemContactsBean();
		mContacts.setImgId(R.drawable.ic_msg);
		mContacts.setReal_name("手机短信");
		mList.add(mContacts);

		List<ContactsBaseBean> temp = new ArrayList<ContactsBaseBean>();
		//获取所有用户
		DatabaseHelperForChattingMap dbHelper7 = new DatabaseHelperForChattingMap(getActivity(), "db", 2);
		ArrayList<SuperFriendsBean> mListSuperFriends = dbHelper7.getSuperFriendsBeanList();
		if(dbHelper7 != null) {
			dbHelper7.close();
		}
		//目前没用
		/*ArrayList<String> mListId2 = findChatUserId();
		for(Iterator<String> iterator=mListId2.iterator();iterator.hasNext();) {
			String name = iterator.next();
			ArrayList<ChatMessageBean> messages = findAllChatMessages(name);

			if (messages != null && !messages.isEmpty()) {
				//				temp.add(c);
				//				c.setLastChatTime(messages.get(messages.size() - 1)
				//						.getReceiveTime());
			}
		}*/
		//对所有的用户进行遍历并且时间搜索
		for (ContactsBaseBean c : mListSuperFriends) {
			/*List<ChatMessageBean> messages = mChatMessageManager
					.findChatMessages(c);*/
			ArrayList<ChatMessageBean> messages = findChatMessages(c);
			//如果没有该用户消息的话

			if (messages != null && !messages.isEmpty()) {
				//				c.setUnreadCount(messages.get(0).getUnreadCount());
				temp.add(c);
				c.setLastChatTime(messages.get(messages.size() - 1)
						.getReceiveTime());
			}
		}
		Collections.sort(temp, new Comparator<ContactsBaseBean>() {

			@Override
			public int compare(ContactsBaseBean lhs, ContactsBaseBean rhs) {
				return (int) (rhs.getLastChatTime() - lhs.getLastChatTime());
			}
		});
		mList.addAll(temp);
		Log.i("tagtest", "loadafter");
		setListAdapter();
		mSwipeRefreshLayout.setRefreshing(false);


	}



	public ArrayList<ChatMessageBean> findChatMessages(ContactsBaseBean base) {
		ArrayList<ChatMessageBean> messages = new ArrayList<ChatMessageBean>();
		try {


			dbHelper7 = new DatabaseHelperForChattingMap(getActivity(), "db", 2);  
			db7 = dbHelper7.getReadableDatabase();  
			//创建游标对象  
			String name;
			if (base instanceof SuperFriendsBean) {
				name = ((SuperFriendsBean) base).getVo_id();
			} else {
				name = base.getPhone();
			}
			
//			String mSelfCode = BaseActivity.getUser(getActivity()).getVo_id();;
			String mSelfCode = userBean.getVo_id();;
			cursor2 = db7.query("UCSMessage", new String[]{"id","idr","chatType","content", "msgFrom","msgId", "msgTo", "receiveTime", "voiceLength", "isread", "UnreadCount"}, "(msgFrom='" + name + "' and msgTo= '" + mSelfCode
					+ "') or (msgFrom='" + mSelfCode
					+ "' and msgTo = '" + name + "')", null, null, null, null, null);  
			//利用游标遍历所有数据对象  
			while(cursor2.moveToNext()){ 
				ChatMessageBean mChatMessageBean = new ChatMessageBean();

				int id = cursor2.getInt(cursor2.getColumnIndex("id"));
				String idr =  cursor2.getString(cursor2.getColumnIndex("idr"));
				String chatType =  cursor2.getString(cursor2.getColumnIndex("chatType"));
				String content =  cursor2.getString(cursor2.getColumnIndex("content"));
				String msgFrom =  cursor2.getString(cursor2.getColumnIndex("msgFrom"));
				String msgId =  cursor2.getString(cursor2.getColumnIndex("msgId"));
				String msgTo =  cursor2.getString(cursor2.getColumnIndex("msgTo"));
				String receiveTime =  cursor2.getString(cursor2.getColumnIndex("receiveTime"));
				String voiceLength =  cursor2.getString(cursor2.getColumnIndex("voiceLength"));
				String isread =  cursor2.getString(cursor2.getColumnIndex("isread"));
				String readcount =  cursor2.getString(cursor2.getColumnIndex("UnreadCount"));
				mChatMessageBean.setId(Integer.parseInt(idr));
				Log.i("TAG", Integer.parseInt(chatType) + "");
				mChatMessageBean.setId(id);
				mChatMessageBean.setChatType(Integer.parseInt(chatType));
				mChatMessageBean.setContent(content);
				mChatMessageBean.setMsgFrom(msgFrom);
				mChatMessageBean.setMsgId(msgId);
				mChatMessageBean.setMsgTo(msgTo);
				mChatMessageBean.setUnreadCount(Integer.parseInt(readcount));
				mChatMessageBean.setReceiveTime(Long.parseLong(receiveTime));;
				mChatMessageBean.setVoiceLenth(Integer.parseInt(voiceLength));
				mChatMessageBean.setHasRead(Integer.parseInt(isread) == 0 ? true : false);
				messages.add(mChatMessageBean);
				//日志打印输出  
			}

		} catch(Exception e) {

		} finally {
			if(cursor2 != null) {
				cursor2.close();
				cursor2 = null;
			}
			if(db7 != null) {
				db7.close();
				db7 = null;
			}
			if(dbHelper7 != null) {
				dbHelper7.close();
				dbHelper7 = null;
			}
		}
		return messages;
	}


	public ArrayList<ChatMessageBean> findAllChatMessages(String name) {
		ArrayList<ChatMessageBean> messages = new ArrayList<ChatMessageBean>();
		try {
			dbHelper7 = new DatabaseHelperForChattingMap(getActivity(), "db", 2);  
			db7 = dbHelper7.getReadableDatabase();  
			//创建游标对象  
			String mSelfCode = userBean.getVo_id();;
			cursor2 = db7.query("UCSMessage", new String[]{"id","idr","chatType","content", "msgFrom","msgId", "msgTo", "receiveTime", "voiceLength", "isread", "UnreadCount"}, "(msgFrom='" + name + "' and msgTo= '" + mSelfCode
					+ "') or (msgFrom='" + mSelfCode
					+ "' and msgTo = '" + name + "')", null, null, null, null, null);  
			//利用游标遍历所有数据对象  
			while(cursor2.moveToNext()){ 
				ChatMessageBean mChatMessageBean = new ChatMessageBean();

				int id = cursor2.getInt(cursor2.getColumnIndex("id"));
				String idr =  cursor2.getString(cursor2.getColumnIndex("idr"));
				String chatType =  cursor2.getString(cursor2.getColumnIndex("chatType"));
				String content =  cursor2.getString(cursor2.getColumnIndex("content"));
				String msgFrom =  cursor2.getString(cursor2.getColumnIndex("msgFrom"));
				String msgId =  cursor2.getString(cursor2.getColumnIndex("msgId"));
				String msgTo =  cursor2.getString(cursor2.getColumnIndex("msgTo"));
				String receiveTime =  cursor2.getString(cursor2.getColumnIndex("receiveTime"));
				String voiceLength =  cursor2.getString(cursor2.getColumnIndex("voiceLength"));
				String isread =  cursor2.getString(cursor2.getColumnIndex("isread"));
				String readcount =  cursor2.getString(cursor2.getColumnIndex("UnreadCount"));
				mChatMessageBean.setId(Integer.parseInt(idr));
				Log.i("TAG", Integer.parseInt(chatType) + "");
				mChatMessageBean.setId(id);
				mChatMessageBean.setChatType(Integer.parseInt(chatType));
				mChatMessageBean.setContent(content);
				mChatMessageBean.setMsgFrom(msgFrom);
				mChatMessageBean.setMsgId(msgId);
				mChatMessageBean.setMsgTo(msgTo);
				mChatMessageBean.setUnreadCount(Integer.parseInt(readcount));
				mChatMessageBean.setReceiveTime(Long.parseLong(receiveTime));;
				mChatMessageBean.setVoiceLenth(Integer.parseInt(voiceLength));
				mChatMessageBean.setHasRead(Integer.parseInt(isread) == 1 ? true : false);
				messages.add(mChatMessageBean);
				//日志打印输出  
			}


		} catch(Exception e) {

		} finally {
			if(cursor2 != null) {
				cursor2.close();
				cursor2 = null;
			}
			if(db7 != null) {
				db7.close();
				db7 = null;
			}
			if(dbHelper7 != null) {
				dbHelper7.close();
				dbHelper7 = null;
			}
		}

		return messages;
	}

	boolean hasString(ArrayList<String> list, String s2) {
		for(Iterator<String> iterator=list.iterator();iterator.hasNext();) {
			String s = iterator.next();
			if(s2.equals(s)) {
				return true;
			}
		}
		return false;
	}


	public ArrayList<String> findChatUserId() {
		ArrayList<String> messages = new ArrayList<String>();
		try {
			dbHelper7 = new DatabaseHelperForChattingMap(getActivity(), "db", 2);  
			db7 = dbHelper7.getReadableDatabase();  
			String mSelfCode = userBean.getVo_id();;
			cursor2 = db7.query("UCSMessage", new String[]{"id","msgFrom","msgTo"}, null, null, new String("msgFrom"), null, null, null);  
			//利用游标遍历所有数据对象  
			while(cursor2.moveToNext()){ 
				ChatMessageBean mChatMessageBean = new ChatMessageBean();
				String msgFrom =  cursor2.getString(cursor2.getColumnIndex("msgFrom"));
				messages.add(msgFrom);
				if(!hasString(messages, msgFrom)) {
					messages.add(msgFrom);
				}
				//日志打印输出  
			}

			cursor2 = db7.query("UCSMessage", new String[]{"id","msgFrom","msgTo"}, null, null, new String("msgTo"), null, null, null);  
			//利用游标遍历所有数据对象  
			while(cursor2.moveToNext()){ 
				ChatMessageBean mChatMessageBean = new ChatMessageBean();
				String msgTo =  cursor2.getString(cursor2.getColumnIndex("msgTo"));
				if(!hasString(messages, msgTo)) {
					messages.add(msgTo);
				}
				//			messages.add(msgFrom);
				//日志打印输出  
			}

		} catch(Exception e) {

		} finally {
			if(cursor2 != null) {
				cursor2.close();
				cursor2 = null;
			}
			if(db7 != null) {
				db7.close();
				db7 = null;
			}
			if(dbHelper7 != null) {
				dbHelper7.close();
				dbHelper7 = null;
			}
		}



		return messages;
	}



	@Override
	public void loadData() {
		// make this call empty,no need here
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		ContactsBaseBean mBase = getItem(position);
		if (position == 1) {

			/*startActivity(new Intent(getActivity(),
					FriendShareListActivity.class).putExtra(Constants.KEY_DATA,
					-3));*/
			startActivity(new Intent(getActivity(),
					EntrepriseDynamicActivity.class).putExtra("from_entreprise", 1));

			//			startActivity(new Intent(getActivity(), FriendsShareWallActivity.class));
		} else if(position == 2) {
			try{

				Utils.toSMSScreen(getActivity());
			} catch (Exception e) {
				try {

					Utils.toSMSScreen2(getActivity());
				} catch(Exception e2) {
					Toast.makeText(getActivity(), "该设备不支持手机短信跳转功能", Toast.LENGTH_LONG).show();
				}

			}
		} else {
			mBase.setUnread(false);
			mBase.setUnreadCount(0);
			DatabaseHelperForChattingMap mHelper = new DatabaseHelperForChattingMap(getActivity(), "db", 2);
			mHelper.resetZero(mBase.getUserid() + "");
			startActivity(new Intent(getActivity(), ChatActivity.class)
			.putExtra(Constants.KEY_DATA, mBase));
			load();

		}
	}

	@Override
	public void refreshMessage() {
		load();
	}

	class UpdateBroadcastReceiver extends BroadcastReceiver {

		public UpdateBroadcastReceiver() {

		}

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			load();
		}

	}

	class UpdateBroadcastReceiver2 extends BroadcastReceiver {

		public UpdateBroadcastReceiver2() {

		}

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			load();
		}

	}


}
